const Router = require('koa-router')
const { success } = require('../../lib/helper')
const { RegisterValidator } = require('../../validators/userValidator')
const { User } = require('../../models/User')

const router = new Router({prefix: '/admin/user'})

router.post('/register', async(ctx) => {
  const v = await new RegisterValidator().validate(ctx)
  const user = {
    userName: v.get('body.userName'),
    password: v.get('body.password')
  }
  await User.create(user)
  success('注册成功')
})

// module.exports = { router } // 这种导出路由的方式也支持
module.exports = router